import csv
import sys
import json
from pymongo import MongoClient
import pandas as pd


def mongoimport(csv_path, db_name, coll_name, db_url):
    """ Imports a csv file at path csv_name to a mongo colection
    returns: count of the documants in the new collection
    """
    client = MongoClient(db_url)
    db = client[db_name]
    coll = db[coll_name]
    data = pd.read_csv(csv_path)
    payload = json.loads(data.to_json(orient='records'))
    coll.insert_many(payload)
    return coll.count_documents({})


if __name__ == '__main__':
    ret = mongoimport(sys.argv[1], "yqsl", "wifi_scan_869516056696110", "mongodb://")
    print("import from csv of count ", ret)
